package com.kensure.shike.baobei.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import co.kensure.frame.JSBaseService;
import co.kensure.mem.CollectionUtils;
import co.kensure.mem.MapUtils;
import co.kensure.mem.NumberUtils;

import com.kensure.basekey.BaseKeyService;
import com.kensure.shike.baobei.dao.SKBaobeiTagDao;
import com.kensure.shike.baobei.model.SKBaobei;
import com.kensure.shike.baobei.model.SKBaobeiTag;

/**
 * 商品标签关系表 服务实现类
 * 
 * @author fankd created on 2019-7-9
 * @since
 */
@Service
public class SKBaobeiTagService extends JSBaseService {

	@Resource
	private SKBaobeiTagDao dao;
	@Resource
	private BaseKeyService baseKeyService;

	public SKBaobeiTag selectOne(Long id) {
		return dao.selectOne(id);
	}

	public List<SKBaobeiTag> selectByIds(Collection<Long> ids) {
		return dao.selectByIds(ids);
	}

	public List<SKBaobeiTag> selectAll() {
		return dao.selectAll();
	}

	public List<SKBaobeiTag> selectByWhere(Map<String, Object> parameters) {
		return dao.selectByWhere(parameters);
	}

	public long selectCount() {
		return dao.selectCount();
	}

	public long selectCountByWhere(Map<String, Object> parameters) {
		return dao.selectCountByWhere(parameters);
	}

	public boolean insert(SKBaobeiTag obj) {
		super.beforeInsert(obj);
		obj.setId(baseKeyService.getKey("sk_baobei_tag"));
		return dao.insert(obj);
	}

	public boolean insertInBatch(List<SKBaobeiTag> objs) {
		return dao.insertInBatch(objs);
	}

	public boolean update(SKBaobeiTag obj) {
		return dao.update(obj);
	}

	public boolean updateByMap(Map<String, Object> params) {
		return dao.updateByMap(params);
	}

	public boolean delete(Long id) {
		return dao.delete(id);
	}

	public boolean deleteMulti(Collection<Long> ids) {
		return dao.deleteMulti(ids);
	}

	public boolean deleteByWhere(Map<String, Object> parameters) {
		return dao.deleteByWhere(parameters);
	}

	/**
	 * 根据子类目id获取宝贝
	 * 
	 * @param pid
	 * @return
	 */
	public List<Long> selectByTagid(String tagid) {
		Long tagidlong = NumberUtils.parseLong(tagid, 0L);
		Map<String, Object> parameters = MapUtils.genMap("tagid", tagidlong);
		List<SKBaobeiTag> tags = selectByWhere(parameters);
		if (CollectionUtils.isEmpty(tags)) {
			return null;
		}
		List<Long> idlist = new ArrayList<>();
		for (SKBaobeiTag tag : tags) {
			if (!idlist.contains(tag.getBbid())) {
				idlist.add(tag.getBbid());
			}
		}
		return idlist;
	}

	/**
	 * 根据宝贝id获取类目信息
	 * 
	 * @param pid
	 * @return
	 */
	public List<SKBaobeiTag> getList(Long bbid) {
		Map<String, Object> parameters = MapUtils.genMap("bbid", bbid);
		List<SKBaobeiTag> tags = selectByWhere(parameters);
		return tags;
	}

	
}
